//
//  TGMainViewController.swift
//  TGWeiBo
//
//  Created by 涛哥无敌威武 on 16/4/17.
//  Copyright © 2016年 taoge. All rights reserved.
//

import UIKit

class TGMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //初始化tabbar
        let tabbar = TGTabBar()
        tabbar.TGDeletate = self

        //单独设置一个页面时的步骤
        /*
        let homeVC = TGHomeViewController()
        homeVC.tabBarItem.image = UIImage(named: "tabbar_home")
        homeVC.tabBarItem.selectedImage = UIImage(named: "tabbar_home_selected")
        homeVC.title = "首页"
        addChildViewController(UINavigationController(rootViewController: homeVC))
        */
        setValue(tabbar, forKey: "tabBar")
        
        //添加子控制器
        addChildViewController(TGHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(TGDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(TGMessageViewController(), imageName: "tabbar_message_center", title: "信息")
        addChildViewController(TGProfileViewController(), imageName: "tabbar_profile", title: "我")
    
    }
    
    func addChildViewController(childViewController: UIViewController, imageName: String, title: String){
        
        //设置图片
        childViewController.tabBarItem.image = UIImage(named: imageName)
        //设置选中图片
        childViewController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        //设置标题
        childViewController.title = title
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: childViewController))
    
    }
}

    extension TGMainViewController:TGTabBarDeletate{
        func composeButtonClick(){
        
            print("加号按钮被点击了")
        }
    
    }
    


